import 'package:bxultimate/app/router/router_name.dart';
import 'package:bxultimate/data/request/organization_request.dart';
import 'package:bxultimate/domain/common/result.dart';
import 'package:bxultimate/shared/constant/app_constant.dart';
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
import 'package:get/get.dart';

import 'state.dart';

class OrganizationInformationController extends GetxController {
  final OrganizationInformationState state = OrganizationInformationState();

  final orgId = Get.arguments['orgId'];
  final attributionCode = Get.arguments['attributionCode'];

  @override
  void onInit() {
    // TODO: implement onInit
    super.onInit();
    getData();
  }

  void getData() async {
    SmartDialog.showLoading(msg: '加载中...');
    state.orgInfo = await OrganizationRequest.getTeamInfo(
        Get.arguments['orgId'], Get.arguments['attributionCode']);

    Result result = await OrganizationRequest.getUserTeamRole(state.orgInfo.id);
    state.isAdmin = result.data;
    SmartDialog.dismiss();
  }

  void toContactList() {
    Get.toNamed(RouterName.organizationContactList);
  }

  deleteTeam() async {
    Get.back();
    await OrganizationRequest.deleteTeam(orgId);
    SmartDialog.showNotify(msg: '解散成功', notifyType: NotifyType.success);
    Get.offAllNamed(RouterName.main);
  }

  void outTeam() async{
    Get.back();

    // 检查是否是超级管理员
    Result result = await OrganizationRequest.checkIsSuperTeamSoleAdmin(orgId);

    if(result.code == AppConstant.RESULT_ERROR){
      SmartDialog.showToast(result.message!);
      return;
    }

    // 解散

  }
}
